package com.lyxs916.widget.factory;

import android.support.annotation.DrawableRes;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lyxs916.widget.loading.R;
import com.lyxs916.widget.loading.factory.LoadingFactory;

/**
 * 说明:自定义样式LoadingBar的例子
 * 作者： 杨阳; 创建于：  2017-06-09  16:47
 */
public class CustomLoadingFactory implements LoadingFactory {
    private View loadingView;
    private CharSequence mMsg;
    private int mIcon = -1;

    @Override
    public View onCreateView(ViewGroup parent) {
        loadingView = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_custom, parent, false);
        TextView msg = (TextView) loadingView.findViewById(R.id.tv_message);
        ImageView icon = (ImageView) loadingView.findViewById(R.id.iv_icon);

        if (msg != null && !TextUtils.isEmpty(mMsg)) {
            msg.setText(mMsg);
        }
        if (icon != null && mIcon != -1) {
            icon.setImageResource(mIcon);
        }
        return loadingView;
    }

    /**
     * 说明: 设置提示文本
     * 作者： 杨阳; 创建于：  2017-06-09  17:25
     */
    public CustomLoadingFactory setMessage(CharSequence message) {
        mMsg = message;
        return this;
    }

    /**
     * 说明:设置图标
     * 作者： 杨阳; 创建于：  2017-06-09  17:25
     */
    public CustomLoadingFactory setIcon(@DrawableRes int Resid) {
        mIcon = Resid;
        return this;
    }

}
